/*
--------------------------------------------------------------------------------
				Ak-Lib. 
			 Project       	: Ak-Lib
			 Group         	: Ak-Lib R&D Team
			 Author        	: Ocean.Wang
			 Create Date 	: 05-01-2010
--------------------------------------------------------------------------------
Code Name 	:  A.K 	~v~
Description	:  Yet Another Cross-Platform Lib.
Cautions    	:
--------------------------------------------------------------------------------
Change History:
Version		: 0.1
Building 		: 05/01/10
10-05.01 first draft, build, debug and test.
--------------------------------------------------------------------------------
*/

#ifndef _INC_AK_MSGQ_
#define	_INC_AK_MSGQ_

#include "ak_types.h"
#include "ak_queue.h"
#include "ak_lock.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
	_MSGQ_PRI_HI = 0,
	_MSGQ_PRI_MD = 1,
	_MSGQ_PRI_LO = 2,
	_MSGQ_PRI_MAX
}_e_sysMsgQPri;

#define SMSGQ_MAGIC 		0X1A2B3C4D

typedef struct {
	_t_sysCS 	lock;
	_t_blist	queue;
	_t_sysSemB *wake;
}_t_sysMsgSlot;

typedef struct {
	_t_bnode 	node;
	int 		len;
	int 		reserv;
}_t_sysMsgNode;

typedef struct {
	uInt32 			magic;
	uInt32			msgMaxNum;		
	uInt32			msgMaxLen;

	/* Stat Info */
	uInt32			msgTx;
	uInt32			msgRx;

	_t_sysSemB 		wakeMsg;
	_t_sysSemB 		wakeFree;
	_t_sysMsgSlot 	slots[_MSGQ_PRI_MAX];

	/* Mutex Obj */
	_t_sysMsgSlot 	free;
}_t_sysMsgQ;


extern _t_sysMsgQ	*	SMsgQ_Create(uInt32 msgMaxNum, uInt32 msgMaxLen);
extern sInt32			SMsgQ_Send(_t_sysMsgQ * pMsgQ, void * msgBuf, uInt32 msgLen, sInt32 msgPri, sInt32 timeOut);
extern sInt32			SMsgQ_Recv(_t_sysMsgQ * pMsgQ, void * msgBuf, uInt32 msgLen, sInt32 timeOut);
extern sInt32			SMsgQ_Peek(_t_sysMsgQ * pMsgQ);



#ifdef __cplusplus
}
#endif

#endif


